<?php

namespace app\admin\model;

use app\admin\model\Article;
use think\Model;

class Tap extends Model
{
    static public function handleSpliceToArr(array $tap)
    {
        if (isset($tap)) {
            $keys = array_keys($tap);
            $k = '';
            foreach ($keys as $key) {
                if (is_numeric($key)) {
                    if (!self::findOrEmpty($key)->isEmpty()) {
                        $k .= $key . ',';
                    }
                }
            }
        } else $k = '';
        return $k;
    }
    public function list($type = 'edit')
    {
        if ($type == 'edit') {
            return $this->where('is_show', 1)->select();
        } else {
            return $this->select();
        }
    }
    public function get($articleId)
    {
        $articleTap = Article::where('id', $articleId)->value('tap_id');
        $tapArr = explode(',', $articleTap);
        $list = [];
        foreach ($tapArr as $t) {
            $val = $this->where('id', $t)->value('tap');
            if ($val != '') {
                $list[] = $val;
            }
        }
        return  $list;
    }
}
